﻿using System;
using System.Xml;

namespace TimeTableEasy.src.Core
{
    class Lang
    {
        private static XmlDocument XMLFile;
       
        public Lang(out String error)
        {
            error = null;
            try
            {
                XMLFile = new XmlDocument();
                XMLFile.Load("language/fr_Fr.xml");
            }
            catch (Exception ex)
            {
                error = "An error occur during the loading of the language file.";
                LogMgr.DEBUG_LOG("LANG ERROR : " + ex.Message);
            }
        }

        public static String GetMessage(OpCodes.TimeTableEasyStrings opcode)
        {
            XmlNodeList nodelist = XMLFile.SelectNodes("language/string");
            for (int i = 0; i < nodelist.Count; i++)
            {
                if (int.Parse((nodelist[i].Attributes)[0].Value) == opcode.GetHashCode())
                    return nodelist[i].InnerText;
            }

            return "ERREUR INCONNU";
        }
    }
}
